﻿using Furion;
using Microsoft.AspNetCore.Http;
using System;
using System.Web;

namespace PrivateTracker.NET.Application
{
    public class AnnounceInput
    {
        private string _info_hash;
        public string Info_Hash
        {
            get
            {
                return _info_hash;
            }
            set
            {
                if (!string.IsNullOrWhiteSpace(value))
                {
                    byte[] vs = HttpUtility.UrlDecodeToBytes(value);
                    _info_hash = BitConverter.ToString(vs).Replace("-", string.Empty);
                }
                else
                {
                    _info_hash = value;
                }
            }
        }
        private string _peer_Id;
        public string Peer_Id
        {
            get
            {
                return _peer_Id;
            }
            set
            {
                if (!string.IsNullOrWhiteSpace(value))
                {
                    byte[] vs = HttpUtility.UrlDecodeToBytes(value);
                    _peer_Id = BitConverter.ToString(vs).Replace("-", string.Empty);
                }
                else
                {
                    _peer_Id = value;
                }
            }
        }
        private string _ip;
        public string Ip
        {
            get
            {
                if (string.IsNullOrWhiteSpace(_ip))
                {
                    _ip = App.GetService<IHttpContextAccessor>().HttpContext.GetRemoteIpAddressToIPv4();
                }
                return _ip;
            }
            set
            {
                _ip = value;
            }
        }
        public int Port { get; set; }
        public long Uploaded { get; set; }
        public long Downloaded { get; set; }
        public long Left { get; set; }
        public int Corrupt { get; set; }
        public PeerEvent Event { get; set; }
        private int? _numwant;
        public int? Numwant
        {
            get { return _numwant ?? 50; }//TODO 最终设置全局参数来自后台设置
            set { _numwant = value; }
        }
        public int Compact { get; set; }
        public string PassKey { get; set; }
    }
}